import { http } from './../plugins/axios'

const state = () => ({
    token: '',
    id: '',
    email: '',
    nickname: '',
    avatar: ''
})

const mutations = {
    SET_TOKEN(state, token) {
        state.token = token
    },
    SET_USER(state, user) {
        state.id = user._id
        state.email = user.email
        state.nickname = user.nickname
        state.avatar = user.avatar
    }
}

const actions = {
    detail: async ({ state, commit }, data) => {
        let ret = await http.get('/user/detail')
        if (ret.code === 0) {
            commit('SET_USER', ret.data)
        }
    }
}

export default {
    namesapce: true,
    state,
    mutations,
    actions,
}